//
//  CheckResultItemViewModel.m
//  MobileChecker
//
//  Created by Lymons on 15-1-12.
//  Copyright (c) 2015年 Lymons. All rights reserved.
//

#import "CheckResultItemViewModel.h"
#import "UIDevice+IdentifierAddition.h"

#define SECTION_TITLE_AUTO      @"◆自動診断結果"
#define CELL_TITLE_WIFI         @" WIFI"
#define CELL_TITLE_BLUETOOTH    @" Bluetooth"
#define CELL_TITLE_CENSOR       @" センサー機能"
#define CELL_TITLE_GPS          @"  ・GPS"
#define CELL_TITLE_COMPASS      @"  ・ジャイロ"
#define CELL_TITLE_MAGNE        @"  ・磁気"
#define CELL_TITLE_PROMIXITY    @"  ・近接"
#define CELL_TITLE_LUMIA        @"  ・輝度"
#define SECTION_TITLE_SELF      @"◆セルフ診断結果"
#define CELL_TITLE_VIB          @" バイブ機能"
#define CELL_TITLE_MIC          @" マイク機能"
#define CELL_TITLE_SPEAKER      @" スピーカー機能"
#define CELL_TITLE_TOUCH        @" タッチパネル"
#define CELL_TITLE_DOT          @" ドット抜け"
#define CELL_TITLE_CAM          @" カメラ機能"
#define CELL_TITLE_BUTTERY      @"バッテリー状態"
#define CELL_TITLE_SIM          @"SIMカード"
#define CELL_TITLE_SD           @"SDカード"


@implementation CheckResultItemViewModel

- (instancetype)init
{
    self = [super init];
    if (self) {
        if ([UIDevice currentDevice].hasGPS) {
            [CheckResultUserDefaults standardUserDefaults].simCardCheckResult = [UIDevice currentDevice].hasSimCard ? DiagnosisCheckResultFound : DiagnosisCheckResultNotFound;
        } else {
            [CheckResultUserDefaults standardUserDefaults].simCardCheckResult = DiagnosisCheckResultNoSupport;
        }
        [CheckResultUserDefaults standardUserDefaults].batteryCheckResult = DiagnosisCheckResultUnknown;
        self.items = @[SECTION_TITLE_AUTO,
                       CELL_TITLE_WIFI,
                       CELL_TITLE_BLUETOOTH,
                       CELL_TITLE_CENSOR,
//                       CELL_TITLE_GPS,
                       CELL_TITLE_COMPASS,
                       CELL_TITLE_MAGNE,
                       CELL_TITLE_PROMIXITY,
                       CELL_TITLE_LUMIA,
                       ITEM_RESULT_NONE,
                       SECTION_TITLE_SELF,
                       CELL_TITLE_VIB,
                       CELL_TITLE_MIC,
                       CELL_TITLE_SPEAKER,
                       CELL_TITLE_TOUCH,
                       CELL_TITLE_DOT,
                       CELL_TITLE_CAM,
                       ITEM_RESULT_NONE,
                       CELL_TITLE_BUTTERY,
                       ITEM_RESULT_NONE,
                       CELL_TITLE_SIM,];
        [self updateResult];
    }
    return self;
}

- (void)updateResult
{
    [self.itemsResult removeAllObjects];
    [self.items enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL *stop) {
        [self.itemsResult insertObject:[CheckResultUserDefaults resultString:[self result:obj]] atIndex:idx];
    }];
    
    self.resultString = [CheckResultUserDefaults diagnosisResultString];
}

- (DiagnosisCheckResult)result:(NSString *)name
{
    if ([name isEqualToString:CELL_TITLE_WIFI]) {
        return [CheckResultUserDefaults standardUserDefaults].wifi3gCheckResult;
    } else if ([name isEqualToString:CELL_TITLE_BLUETOOTH]) {
        return [CheckResultUserDefaults standardUserDefaults].bluetoothCheckResult;
    } else if ([name isEqualToString:CELL_TITLE_GPS]) {
        return [CheckResultUserDefaults standardUserDefaults].gpsCheckResult;
    } else if ([name isEqualToString:CELL_TITLE_COMPASS]) {
        return [CheckResultUserDefaults standardUserDefaults].compassCheckResult;
    } else if ([name isEqualToString:CELL_TITLE_MAGNE]) {
        return [CheckResultUserDefaults standardUserDefaults].magneticCheckResult;
    } else if ([name isEqualToString:CELL_TITLE_PROMIXITY]) {
        return [CheckResultUserDefaults standardUserDefaults].proximityCheckResult;
    } else if ([name isEqualToString:CELL_TITLE_LUMIA]) {
        return [CheckResultUserDefaults standardUserDefaults].luminaCheckResult;
    } else if ([name isEqualToString:CELL_TITLE_VIB]) {
        return [CheckResultUserDefaults standardUserDefaults].vibrationCheckResult;
    } else if ([name isEqualToString:CELL_TITLE_MIC]) {
        return [CheckResultUserDefaults standardUserDefaults].recordCheckResult;
    } else if ([name isEqualToString:CELL_TITLE_SPEAKER]) {
        return [CheckResultUserDefaults standardUserDefaults].soundCheckResult;
    } else if ([name isEqualToString:CELL_TITLE_TOUCH]) {
        return [CheckResultUserDefaults standardUserDefaults].touchCheckResult;
    } else if ([name isEqualToString:CELL_TITLE_DOT]) {
        return [CheckResultUserDefaults standardUserDefaults].screenCheckResult;
    } else if ([name isEqualToString:CELL_TITLE_CAM]) {
        return [CheckResultUserDefaults standardUserDefaults].cameraCheckResult;
    } else if ([name isEqualToString:CELL_TITLE_BUTTERY]) {
        return [CheckResultUserDefaults standardUserDefaults].batteryCheckResult;
    } else if ([name isEqualToString:CELL_TITLE_SIM]) {
        return [CheckResultUserDefaults standardUserDefaults].simCardCheckResult;
    } else if ([name isEqualToString:CELL_TITLE_SD]) {
        return DiagnosisCheckResultNotFound;
    } else if ([name isEqualToString:SECTION_TITLE_AUTO]) {
        return DiagnosisCheckResultNone;
    } else if ([name isEqualToString:SECTION_TITLE_SELF]) {
        return DiagnosisCheckResultNone;
    } else if ([name isEqualToString:CELL_TITLE_CENSOR]) {
        return DiagnosisCheckResultNone;
    }
    
    return DiagnosisCheckResultNoCheck;
}

@end
